﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HCQ2_Common
{
    /// <summary>
    ///  随机数帮助类
    /// </summary>
    public static class RandomHelper
    {
        private static string zimu = "abcdefghijklmnopqrstuvwxyz";
        /// <summary>
        ///  获取指定区间的一个随机数
        /// </summary>
        /// <param name="start">开区间</param>
        /// <param name="end">闭区间</param>
        /// <returns></returns>
        public static int GetSingleInt(int start,int end)
        {
            if (end <= 0)
                return 0;
            Random rand = new Random();
            return rand.Next(start, end);
        }
        /// <summary>
        ///  获取指定区间，指定个数随机数集合
        /// </summary>
        /// <param name="start">开区间</param>
        /// <param name="end">闭区间</param>
        /// <param name="len">随机个数</param>
        /// <returns></returns>
        public static List<int> GetListInt(int start, int end,int len)
        {
            if (end <= 0 || len <= 0)
                return null;
            List<int> list = new List<int>();
            Enumerable.Range(start, end).OrderBy(x => Guid.NewGuid()).Take(len).ToList().ForEach(x => list.Add(x));
            return list;
        }
        /// <summary>
        ///  随机获取一个字母
        /// </summary>
        /// <returns></returns>
        public static string GetSingleZiMu()
        {
            int index = GetSingleInt(1, zimu.Length);
            return zimu.Substring(index - 1, 1);
        }
    }
}
